package com.demo.hystrix.ribbon.client.sevice;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    // 负载均衡消费
    @HystrixCommand(fallbackMethod = "fallback")
    public String hello() {
        return this.restTemplate.getForObject("http://hystrix-ribbon-server/hello/hi", String.class);
    }

    //短路器打开时，执行此函数
    public String fallback() {
        return "Error";
    }
}
